/* 
 *  <copyright file="RaiseLogEvent.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using Microsoft.Xna.Framework;
using SobrietyEngine.Guids;

namespace SobrietyEngine.Events
{
    public class Event
    {
        public Type Type { get; private set; }

        private CGuid from;
        public CGuid From
        {
            get { return from; }
            private set { from = value; }
        }

        public Object RaisedBy { get; set; }

        private GameTime time; //the timeInMs of this event
        public GameTime Time
        {
            get { return time; }
            set { time = value; }
        }

        private IEventData data; //data for this event
        public IEventData Data
        {
            get { return data; }
            private set { data = value; }
        }

        //for event routing?
        //object id to send this event to, defaults to * or 0 for all
        private String to;
        public String To
        {
            get { return to; }
            private set { to = value; }
        }

        public override string ToString()
        {
            String str = "Event( ";
            if(Type!=null)
                str += "Type: " + Type.ToString() + ", ";
            if (RaisedBy != null)
                str += "RaisedBy: " + RaisedBy.ToString() + ", ";
            if(From != null)
                str += "FromGuid: " + From.ToString() + ", ";
            str += ")";
            return str;
        }

        public Event(Object raisedBy, IEventData _data)
        {
            RaisedBy = raisedBy;
            Type = _data.GetType();
            data = _data;
        }

        public Event(Object raisedBy, IEventData _data, CGuid _from)
        {
            RaisedBy = raisedBy;
            Type = _data.GetType();
            from = _from;
            data = _data;
        }

        public void Clear()
        {
            Type = null;
            from = null;
            RaisedBy = null;
            time = null;
            data = null;
            to = "";
        }

        //for pooling
        public Event NewPoolEvent(Object raisedBy, IEventData _data)
        {
            Clear();
            RaisedBy = raisedBy;
            Type = _data.GetType();
            data = _data;
            return this;
        }

        public Event NewPoolEvent(Object raisedBy, IEventData _data, CGuid _from)
        {
            Clear();
            RaisedBy = raisedBy;
            Type = _data.GetType();
            from = _from;
            data = _data;
            return this;
        }

        //for event processing
        //Int16 viewsLeft; //number of objects that can respond to this
    }
}